#include <iostream>
#include "EasyBMP.h"
#include "neurnet.h"
#include "image.h"
#include <string.h>

using namespace std;


int	verboose=0;
int color=0;
int sec=60;
int iter=0;
int snr=0;
int indx=4;

Image*	img;

void showWelcome();
void showUsage();

int main(int argc, char* argv[])
{
	img=new Image();

	showWelcome();

	if(argc<4)
	{
		showUsage();
		return 0;
	}

	while(indx<argc)
	{
		// prelucrez intarea
		if(strcmp(argv[indx],"--color")==0)
		{
			color=1;
			indx++;
			continue;
		}

		if(strcmp(argv[indx],"--verboose")==0)
		{
			verboose=1;
			indx++;
			continue;
		}

		if((strcmp(argv[indx],"--sec")==0)&&(indx+1<argc))
		{
			sec=atoi(argv[indx+1]);
			indx+=2;
			continue;
		}

		if((strcmp(argv[indx],"--snr")==0)&&(indx+1<argc))
		{
			snr=atoi(argv[indx+1]);
			indx+=2;
			continue;
		}

		if((strcmp(argv[indx],"--iter")==0)&&(indx+1<argc))
		{
			iter=atoi(argv[indx+1]);
			indx+=2;
			continue;
		}
		cout<<" "<<argv[indx]<<": unknonw option\n";
		indx++;
	}

	// operatiile de baza
	if(argv[1][0]=='c')
	{
		img->fromBMPtoNN(argv[2],argv[3],color,16,sec,iter,snr,5,verboose);
		delete img;
		cout<<"\n\n Thank you for using NNComp!\n";
		return 0;
	}
	if(argv[1][0]=='d')
	{
		img->fromNNtoBMP(argv[2],argv[3],verboose);
		delete img;
		cout<<"\n\n Thank you for using NNComp!\n";
		return 0;
	}
	
	showUsage();
	return 0;
}


void showWelcome()
{
	// Mesajul de bine ati venit
	cout<<"ncompress - neural network image compressor\n";
}

void showUsage()
{
	cout<<"\nussage: ncompress {c|d} <source> <destination> [OPTIONS]\n\n";
	cout<<"ARGUMENTS: c=compress\n";
	cout<<"           d=decompress\n\n";
	cout<<"OPTIONS:   --color     try to compress color images (not working now)\n";
	cout<<"           --verboose  detailed information on what's happening\n\n";
	cout<<"           --sec <sec> (for compression) maximum compression time in seconds\n";
	cout<<"           --iter <it> (for compression) maximum iterations\n";
	cout<<"           --snr <SNR> (for compression) desired SNR (Sound to Noise Ratio\n";
	cout<<"EXAMPLE:   nncomp c party.bmp party.nn --sec 60 \n\n";
}
